﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Progetto.Beans;

namespace Progetto.Model_Stuff
{
    class Model
    {
        private Dictionary<string, User> _userList = new Dictionary<string, User>();
        private Dictionary<User, List<MyCalendar>> _userCalendarsList = new Dictionary<User, List<MyCalendar>>();
        private Dictionary<User, List<IFilterDescriptor>> _userFiltersList = new Dictionary<User, List<IFilterDescriptor>>();
        private MyCalendar _generalCalendar = new MyCalendar("General Calendar");

        public MyCalendar GeneralCalendar
        {
            get { return _generalCalendar; }
            set { _generalCalendar = value; }
        }

        public Dictionary<string, User> UserList
        {
            get { return _userList; }
            set { _userList = value; }
        }

        public Dictionary<User, List<MyCalendar>> UserCalendarsList
        {
            get { return _userCalendarsList; }
            set { _userCalendarsList = value; }
        }

        public Dictionary<User, List<IFilterDescriptor>> UserFiltersList
        {
            get { return _userFiltersList; }
            set { _userFiltersList = value; }
        }

        public void AddCalendar(User user, MyCalendar calendar)
        {
            _userCalendarsList[user].Add(calendar);
        }

        public void AddFilter(User user, IFilterDescriptor filter)
        {
            _userFiltersList[user].Add(filter);
        }

        public void AddPublicEvent(Event e)
        {
            _generalCalendar.AddEvent(e);
        }

        public void AddEvent(User user, List<MyCalendar> calendars, Event e)
        {
            
            foreach (MyCalendar calendar in calendars) 
            {
                int i = 0;
                foreach (MyCalendar userCalendar in _userCalendarsList[user]) 
                {
                    if (userCalendar.Name == calendar.Name)
                        _userCalendarsList[user][i].AddEvent(e);
                    i++;
                }
            }
        }

        private void refreshFileXml() 
        {
        }
    }
}
